Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add record/split_pair and record/disjoint_merge #1982

Merged
merged 1 commit into from
Jul 3, 2024

Conversation

yannham
Copy link
Member

@yannham yannham commented Jul 1, 2024

This is preliminary work for the rewriting of native contracts using the new immediate/delayed representation introduced in #1975, although this PR is fairly well-separated (and this is why this is a small separate PR).

In order to efficiently implement the contracts for static record types, which needs to know which fields to lock in the sealed tail, we need a way to split and recombine records which is efficient and preserves field metadata. The current implementation can do without because the immediate part and the delayed part are crammed into one function, and the current implementation is also probably quite inefficient (computing 2 record-as-sets differences in pure Nickel).

This PR adds two primops:

  • record/split_pair corresponds exactly to what the Rust code eval::merge::split::split is doing: separate a pair of records into 4 parts, the fields that are in one of the operands but not the other, plus the fields that are common (but which is split in two because we have to choose if we take the value and field metadata's from the left operand or from the right operand).
  • record/disjoint_merge is a fast merge operation when both operands are known to be disjoints. It's closer to a union than a merge, although both coincide on such a special case, in that it doesn't interact with metadata or recursive definitions (although it does preserve metadata). This operation just puts everything in one record.

Those primops might be also useful to efficiently implement other operations (record differences, record projection, etc.) in the stdlibin the future.

This is preliminary work for the rewriting of native contracts using the
(to be introduced in a coming PR) new immediate/delayed representation.
In particular, in order to efficiently implement the contracts for
static record types, we need a way to split and recombine record which
is efficient and preserves field metadata.

Those primops might be useful to efficiently implement other operations
(record differences, record projection, etc.)
@yannham yannham requested review from jneem and vkleen July 1, 2024 16:52
@github-actions github-actions bot temporarily deployed to pull request July 1, 2024 16:55 Inactive
core/src/eval/operation.rs Show resolved Hide resolved
@yannham yannham added this pull request to the merge queue Jul 3, 2024
Merged via the queue into master with commit 3bafeff Jul 3, 2024
5 checks passed
@yannham yannham deleted the task/record-split-primops branch July 3, 2024 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants